package com.example.device.vm

import com.example.common.view.vm.BaseViewModel
import com.example.device.api.DeviceApiService
import com.example.device.entity.MaintainEntity
import com.example.device.model.DeviceRepository
import com.example.device.model.DeviceResultData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class MaintainAddViewModel @Inject constructor(private val apiService: DeviceApiService) : BaseViewModel<DeviceRepository,DeviceResultData<MaintainEntity>>() {
    fun postMaintain(maintainEntity: MaintainEntity){
        mViewModelScope.launch (mDispatcher){
            try {
                val result = apiService.postMaintain(maintainEntity)
                mSuccessLiveData.postValue(result)
            }catch (e:Exception){
                mErrorLiveData.postValue("请求失败:${e.message}")
            }
        }
    }
}